package com.Dao.Imp;
import com.Dao.HeadImageDao;
import com.Utils.C3P0Utils;
import com.pojo.HeadImage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Service;
import java.sql.SQLException;
import java.util.List;
@Service
@Slf4j
public class HeadImageDaoImp implements HeadImageDao {
    @Override
    public List<HeadImage> loadHeadImage(String username) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(C3P0Utils.getDataSource());
        String sql="select username,userAvatar,identify from userList where username=?";
        List<HeadImage> headImage=queryRunner.query(sql,new BeanListHandler<>(HeadImage.class),username);
        return headImage;
    }
    @Override
    public void updateMyHeadImage(String username,String ImageUrl) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(C3P0Utils.getDataSource());
        String sql="update userlist set userAvatar=? where username=?";
        String Url="http://localhost:8080/img/"+ImageUrl;
        queryRunner.update(sql,Url,username);
    }
}
